<% layout('/layouts/default.html', {title: '来文登记表管理', libs: ['validate','dataGrid']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header with-border">
			<div class="box-title">
				<i class="fa icon-note"></i> ${text('确定领文信息' )}
			</div>
			<div class="box-tools pull-right">
				<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
			</div>
		</div>
		<#form:form id="inputForm" model="${docRecv}" action="${ctx}/sd/docRecv/save" method="post" class="form-horizontal">
		<div class="box-body">
			<div class="form-unit">${text('基本信息')}</div>
			<#form:hidden id="id" path="id"/>
			<div class="row">
				<div class="col-xs-12">
					<div class="form-group">
						<label class="control-label col-sm-2" title="">
							<span class="required ">*</span> ${text('来文标题')}：<i class="fa icon-question hide"></i></label>
						<div class="col-sm-10">
							<#form:input path="docTitle" autocomplete="off" maxlength="500" class="form-control required"/>
						</div>
					</div>
				</div>
				<div class="col-xs-6">
					<div class="form-group">
						<label class="control-label col-sm-4" title="">
							<span class="required ">*</span> ${text('来文文号')}：<i class="fa icon-question hide"></i></label>
						<div class="col-sm-8">
							<#form:input path="docFullNum" autocomplete="off" maxlength="100" class="form-control required"/>
						</div>
					</div>
				</div>

				<div class="col-xs-6">
					<div class="form-group">
						<label class="control-label col-sm-4" title="">
							<span class="required ">*</span> ${text('来文类型')}：<i class="fa icon-question hide"></i></label>
						<div class="col-sm-8">
							<#form:select path="docType" dictType="recv_doc_type" class="form-control required" />
						</div>
					</div>
				</div>

				<div class="col-xs-6">
					<div class="form-group">
						<label class="control-label col-sm-4" title="">
							<span class="required ">*</span> ${text('密级')}：<i class="fa icon-question hide"></i></label>
						<div class="col-sm-8">
							<#form:select path="secLvl" dictType="recv_sec_lvl" class="form-control required" />
						</div>
					</div>
				</div>

				<div class="col-xs-6">
					<div class="form-group">
						<label class="control-label col-sm-4" title="">
							<span class="required ">*</span> ${text('紧急程度')}：<i class="fa icon-question hide"></i></label>
						<div class="col-sm-8">
							<#form:select path="docEmergLvl" dictType="recv_doc_emerg_lvl" class="form-control required" />
						</div>
					</div>
				</div>

				<div class="col-xs-6">
					<div class="form-group">
						<label class="control-label col-sm-4" title="">
							<span class="required ">*</span> ${text('来文单位')}：<i class="fa icon-question hide"></i></label>
						<div class="col-sm-8">
							<#form:treeselect id="testUser"  callbackFuncName="selectCallback" title="来文单位选择" path="unitCode" labelPath="uppUnit.unitName"
							url="${ctx}/sd/uppUnit/treeData" allowClear="true"/>
						</div>
					</div>
				</div>
				<div class="col-xs-6">
					<div class="form-group">
						<label class="control-label col-sm-4" title="">
							<span class="required ">*</span> ${text('来文自编号(自定义编号)')}：<i class="fa icon-question hide"></i></label>
						<div class="col-sm-8">
							<#form:input path="docSysCode" placeholder="选择来文单位后自动生成" maxlength="100" readonly="true" class="form-control required"/>
						</div>
					</div>
				</div>

				<div class="col-xs-6">
					<div class="form-group">
						<label class="control-label col-sm-4" title="">
							<span class="required ">*</span> ${text('来文日期')}：<i class="fa icon-question hide"></i></label>
						<div class="col-sm-8">
							<#form:input path="docRecvDate" readonly="true" maxlength="20" class="form-control laydate required"
							dataFormat="date" data-type="date" data-format="yyyy-MM-dd"/>
						</div>
					</div>
				</div>
				<div class="col-xs-6">
					<div class="form-group">
						<label class="control-label col-sm-4" title="">
							<span class="required ">*</span> ${text('来文份数')}：<i class="fa icon-question hide"></i></label>
						<div class="col-sm-8">
							<#form:input path="fileCount" maxlength="4" class="form-control required digits"/>
						</div>
					</div>
				</div>
				<div class="col-xs-6">
					<div class="form-group">
						<label class="control-label col-sm-4" title="">
							<span class="required ">*</span> ${text('每份页数')}：<i class="fa icon-question hide"></i></label>
						<div class="col-sm-8">
							<#form:input path="pageCount" maxlength="5" class="form-control required digits"/>
						</div>
					</div>
				</div>

				<% if(docRecv.isNewRecord){ %>
				<div class="col-xs-6">
					<div class="form-group">
						<label class="control-label col-sm-4" title="">
							<span class="required ">*</span> ${text('是否拟办')}：<i class="fa icon-question hide"></i></label>
						<div class="col-sm-8">
							<#form:radio path="isProposed" dictType="recv_is_proposed" class="form-control required"/>
						</div>
					</div>
				</div>
				<% } %>
			</div>
			<div class="row">
				<div class="col-xs-12">
					<div class="form-group">
						<label class="control-label col-sm-2" title="">
							<span class="required hide">*</span> ${text('摘要')}：<i class="fa icon-question hide"></i></label>
						<div class="col-sm-10">
							<#form:textarea path="remarks" rows="4" maxlength="500" class="form-control"/>
						</div>
					</div>
				</div>
			</div>
		</div>
		<div class="box-footer">
			<div class="row">
				<div class="col-sm-offset-2 col-sm-10">
					<div class="col-sm-10">
						<% if (hasPermi('sd:docRecv:edit')){ %>
						<button type="submit" class="btn btn-sm btn-primary " id="btnSubmit"><i class="fa fa-check"></i> ${text('保 存')}</button>&nbsp;
						<%}%>
						<button type="button" class="btn btn-sm btn-default" id="btnCancel" onclick="js.closeCurrentTabPage()"><i class="fa fa-reply-all"></i> ${text('关 闭')}</button>
					</div>
					<div class="col-sm-2">
						<% if(!docRecv.isNewRecord){ %>
						<button type="button" class="btn btn-sm btn-default" id="btn" onclick="deliverDoc()"><i class="fa fa-share-square"></i> ${text('分 发')}</button>
						<%}%>
					</div>

				</div>
			</div>
		</div>
	</#form:form>
</div>
</div>
<% } %>
<script>
	/*选择来文单位时触发的事件*/
function selectCallback(id, act, index, layero, nodes){
	if (act === 'ok') {
		js.ajaxSubmit("${ctx}/sd/docRecv/getGenSysCode?unitId=" + nodes[0].id, function (data) {
			console.log(data);
			$("#docSysCode").val(data);
		}, null, null, js.text(""))
	}else if(act === 'clear'){
		$("#docSysCode").val('');
	}
}
$("#inputForm").validate({
	submitHandler: function(form){
		js.ajaxSubmitForm($(form), function(data){
			js.showMessage(data.message);
			if(data.result == Global.TRUE){
				js.closeCurrentTabPage(function(contentWindow){
					contentWindow.page();
				});
			}
		}, "json");
	}
});

	//分发文件
	function deliverDoc() {
		var id = $('#id').val();
		js.layer.open({
			type: 2,
			area: [(js.layer.window.outerWidth-200)+'px',(js.layer.window.outerHeight-200)+'px'],
			title: '${text("将文件分发给指定单位")}',
			resize: false,
			scrollbar: true,
			maxmin:true,
			content: '${ctx}/sd/docRecv/toDistribute?id='+id,
			success: function(layero, index){

			},
			btn: ['<i class="fa fa-check"></i> ${text("分发")}',
				'<i class="fa fa-remove"></i> ${text("关闭")}'],
			btn1: function(index, layero){
				var win = layero.iframeWindow();
				var form = {
					inputForm: win.$('#inputForm'),
					btnSubmit: win.$('#btnSubmit'),
				};
				var dataScopeData = [];
				$.each(win.dataScopeTrees, function(key, dataScopeTree){
					var treeNodes = dataScopeTree.getCheckedNodes(true);
					for(var i=0; i<treeNodes.length; i++) {
						dataScopeData.push({
							ctrlType: key, ctrlData: treeNodes[i].id
						});
					}
				});
				win.$("#userDataScopeListJson").val(JSON.stringify(dataScopeData));
				if (win.$('#d1').val() == '') {
					js.layer.msg('领文日期不能为空!', {icon: 5});
					return false;
				}
				if (win.$('#d2').val() == '') {
					js.layer.msg('还文日期不能为空!', {icon: 5});
					return false;
				}
				if (dataScopeData.length == 0) {
					js.layer.msg('分发单位不能为空!', {icon: 5});
					return false;
				}
				let isPrint = win.$('#isPrint1').parent().hasClass('checked');
				js.ajaxSubmitForm(form.inputForm, function(data){


					if(data.result == Global.TRUE){
						js.showMessage(data.message);

						/*if(data.message.search("二维码打印失败") != -1){
							js.showMessage(data.message,'','',5000);
						}else {
							js.showMessage(data.message);
						}*/

						js.layer.closeAll();
						page();
						console.log(JSON.stringify(data.data));
						if(isPrint){
							console.log("in...")
							$.ajax({
								headers: {
									'Accept': 'application/json',
									'Content-Type': 'application/json'
								},
								contentType: "application/json",
								type: "POST",
								url: "${ctx}/sd/docRecv/printCodeByList",
								data: JSON.stringify(data.data),
								dataType: "json",
								traditional: true,
								success: function (data) {
									js.showMessage(data.message);
								}
							});
						}
						return true;
					}else{
						js.layer.msg(data.message, {icon: 5});
					}

					page();
				}, "json");
				return false;
			}
		});
	}
</script>
